//
//  WBStatusRetweetView.swift
//  Weibo
//
//  Created by xu on 2017/3/24.
//  Copyright © 2017年 xuantong. All rights reserved.
//

import UIKit
import SnapKit

class WBStatusRetweetView: UIView {

    
    var retweetViewBottomConstraint: Constraint?
    
    
    var statusViewModel:WBStatusViewModel? {
        
        //重写set方法
        didSet {

            
            //给文字赋值--(// 微博正文进行赋值)
//            contentLabel.text = statusViewModel?.homeModel?.retweeted_status?.text
            
            contentLabel.attributedText = statusViewModel?.retweeAttributedString
            
            //卸载约束
            retweetViewBottomConstraint?.deactivate()
            
            //转发的配图 (这个判断代表是有配图)
            if let picUrls = statusViewModel?.homeModel?.retweeted_status?.pic_urls, picUrls.count > 0{
                
                // 赋值
                pictureView.picUrls = picUrls
               
                //重设置 自己(微博原创)的约束
                self.snp.makeConstraints({ (make) in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                })
                
                //显示图片视图
                pictureView.isHidden = false
                
            }else{
                
                self.snp.makeConstraints({ (make) in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                //隐藏
                pictureView.isHidden = true
            }

        }
    
    }
    //重写父类构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        self.backgroundColor = UIColor(white: 235/255, alpha: 1)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 设置视图
    private func setupUI(){
        //添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        //约束
        contentLabel.snp.makeConstraints { (make) in
            make.left.top.equalTo(10)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        pictureView.snp.makeConstraints { (make) in
        
            make.left.equalTo(self).offset(10)
            make.top.equalTo(contentLabel.snp.bottom).offset(10)
        }
        
        self.snp.makeConstraints { (make) in
           retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }


    }
   
    
    private lazy var contentLabel:UILabel = UILabel(title: "转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文转发微博正文", fontSize: FONTSIZEOFNORMAL, textColor: UIColor.darkGray)
    
    
    //collectionView-- 转发配图
    private lazy var pictureView:WBStatusPictureView = WBStatusPictureView()

    

 }
